package com.health.tablebean.webservice;

import android.content.Context;
import android.text.TextUtils;

import com.health.db.FDbManager;
import com.health.tablebean.ARCHIVE_BASEINFO;
import com.health.tablebean.CD_TUBERCULOSIS_BASEINFO;
import com.health.viewscontrols.NovaApplication;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * 肺结核第一次入户随访上传接口参数（基本信息）
 *
 * @author wangxiangyi
 * @date 2018/05/05
 */
public class TuberculosisBaseInfo {

    /**
     * 患者类型：
     * 初治：DM102-01_1，
     * 复治：DM102-01_2
     */
    private String tuberType;
    /**
     * 痰菌情况：
     * 阳性：DM102-02_1，
     * 阴性：DM102-02_2，
     * 未查痰：DM102-02_3
     */
    private String tuberTjqk;
    /**
     * 耐药情况：
     * 耐药：DM102-03_1，
     * 非耐药：DM102-03_2，
     * 未检测：DM102-03_3
     */
    private String tuberNyqk;
    /**
     * 症状及体征：
     * DM102-04_0 没有症状，
     * DM102-04_1咳嗽咳痰，
     * DM102-04_2低热盗汗，
     * DM102-04_3咯血或血痰，
     * DM102-04_4胸痛消瘦，
     * DM102-04_5恶心纳差，
     * DM102-04_7头痛失眠，
     * DM102-04_8视物模糊，
     * DM102-04_9皮肤瘙痒、皮疹，
     * DM102-04_10耳鸣、听力下降"
     */
    private String tuberZztz;
    /**
     * 用药_用法：
     * 每日：DM102-05_1，
     * 间歇：DM102-05_2
     */
    private String tuberYf;
    /**
     * 用药_药品剂型：
     * 固定剂量复合制剂:DM102-06_1，
     * 散装药:DM102-06_2，
     * 板式组合药:DM102-06_3，
     * 注射剂:DM102-06_4
     */
    private String tuberYpjx;
    /**
     * 单独的居室：
     * 有：DM01-102_1，
     * 无：DM01-102_2
     */
    private String tuberDdjs;
    /**
     * 通风情况：
     * 良好：DM01-69_1，
     * 一般：DM01-69_2，
     * 差：DM01-69_3
     */
    private String tuberTfqk;
    /**
     * 取药地点
     */
    private String tuberQydd;
    /**
     * 取药时间
     */
    private String tuberQysj;
    /**
     * 服药记录卡的填写：
     * 掌握：DM102-08_1，
     * 未掌握：DM102-08_2
     */
    private String tuberJlk;
    /**
     * 服药方法及药品存放：
     * 掌握：DM102-08_1，
     * 未掌握：DM102-08_2
     */
    private String tuberFyff;
    /**
     * 肺结核治疗疗程：
     * 掌握：DM102-08_1，
     * 未掌握：DM102-08_2
     */
    private String tuberZllc;
    /**
     * 不规律服药危害：
     * 掌握：DM102-08_1，
     * 未掌握：DM102-08_2
     */
    private String tuberWh;
    /**
     * 服药后不良反应及处理：
     * 掌握：DM102-08_1，
     * 未掌握：DM102-08_2
     */
    private String tuberBlfy;
    /**
     * 治疗期间复诊查痰：
     * 掌握：DM102-08_1，
     * 未掌握：DM102-08_2
     */
    private String tuberFzct;
    /**
     * 外出期间如何坚持服药：
     * 掌握：DM102-08_1，
     * 未掌握：DM102-08_2
     */
    private String tuberRhfy;
    /**
     * 生活习惯及注意事项：
     * 掌握：DM102-08_1，
     * 未掌握：DM102-08_2
     */
    private String tuberShxg;
    /**
     * 密切接触者检查：
     * 掌握：DM102-08_1，
     * 未掌握：DM102-08_2
     */
    private String tuberJczjc;
    /**
     * 症状及体征其他
     */
    private String tuberZzqt;
    /**
     * 用药_化疗方案
     */
    private String tuberHlfa;
    /**
     * 身份证号（必填）
     */
    private String cardid;
    /**
     * 下次随访时间（必填）
     */
    private String nextVisitDate;
    /**
     * 创建机构（必填）
     */
    private String createorg;
    /**
     * 目标吸烟量
     */
    private String targetSmoke;
    /**
     * 目标饮酒量
     */
    private String targetDrink;
    /**
     * 缺项值（必填）
     */
    private String qdqxz;
    /**
     * 完整度（必填）
     */
    private String wzd;
    /**
     * 创建人（必填）
     */
    private String creater;
    /**
     * 创建时间（必填）
     */
    private String createtime;
    /**
     * 修改机构（必填）
     */
    private String updateorg;
    /**
     * 修改时间（必填）
     */
    private String updatetime;
    /**
     * 修改人（必填）
     */
    private String modified;
    /**
     * 随访时间（必填）
     */
    private String happentime;
    /**
     * 督导人员选择：
     * 医生：DM102-07_1，
     * 家属：DM102-07_2，
     * 自服药：DM102-07_3，
     * 其他：DM102-07_4
     */
    private String tuberDdryxz;
    /**
     * 评估医生签字（必填）
     */
    private String tuberPgysqm;
    /**
     * 随访方式：
     * 门诊：DM04-15_1，
     * 家庭：DM04-15_2
     */
    private String visitWay;
    /**
     * 日吸烟量
     */
    private String smoke;
    /**
     * 日饮酒量
     */
    private String drink;

    public String getTuberType() {
        return tuberType;
    }

    public void setTuberType(String tuberType) {
        this.tuberType = tuberType;
    }

    public String getTuberTjqk() {
        return tuberTjqk;
    }

    public void setTuberTjqk(String tuberTjqk) {
        this.tuberTjqk = tuberTjqk;
    }

    public String getTuberNyqk() {
        return tuberNyqk;
    }

    public void setTuberNyqk(String tuberNyqk) {
        this.tuberNyqk = tuberNyqk;
    }

    public String getTuberZztz() {
        return tuberZztz;
    }

    public void setTuberZztz(String tuberZztz) {
        this.tuberZztz = tuberZztz;
    }

    public String getTuberYf() {
        return tuberYf;
    }

    public void setTuberYf(String tuberYf) {
        this.tuberYf = tuberYf;
    }

    public String getTuberYpjx() {
        return tuberYpjx;
    }

    public void setTuberYpjx(String tuberYpjx) {
        this.tuberYpjx = tuberYpjx;
    }

    public String getTuberDdjs() {
        return tuberDdjs;
    }

    public void setTuberDdjs(String tuberDdjs) {
        this.tuberDdjs = tuberDdjs;
    }

    public String getTuberTfqk() {
        return tuberTfqk;
    }

    public void setTuberTfqk(String tuberTfqk) {
        this.tuberTfqk = tuberTfqk;
    }

    public String getTuberQydd() {
        return tuberQydd;
    }

    public void setTuberQydd(String tuberQydd) {
        this.tuberQydd = tuberQydd;
    }

    public String getTuberQysj() {
        return tuberQysj;
    }

    public void setTuberQysj(String tuberQysj) {
        this.tuberQysj = tuberQysj;
    }

    public String getTuberJlk() {
        return tuberJlk;
    }

    public void setTuberJlk(String tuberJlk) {
        this.tuberJlk = tuberJlk;
    }

    public String getTuberFyff() {
        return tuberFyff;
    }

    public void setTuberFyff(String tuberFyff) {
        this.tuberFyff = tuberFyff;
    }

    public String getTuberZllc() {
        return tuberZllc;
    }

    public void setTuberZllc(String tuberZllc) {
        this.tuberZllc = tuberZllc;
    }

    public String getTuberWh() {
        return tuberWh;
    }

    public void setTuberWh(String tuberWh) {
        this.tuberWh = tuberWh;
    }

    public String getTuberBlfy() {
        return tuberBlfy;
    }

    public void setTuberBlfy(String tuberBlfy) {
        this.tuberBlfy = tuberBlfy;
    }

    public String getTuberFzct() {
        return tuberFzct;
    }

    public void setTuberFzct(String tuberFzct) {
        this.tuberFzct = tuberFzct;
    }

    public String getTuberRhfy() {
        return tuberRhfy;
    }

    public void setTuberRhfy(String tuberRhfy) {
        this.tuberRhfy = tuberRhfy;
    }

    public String getTuberShxg() {
        return tuberShxg;
    }

    public void setTuberShxg(String tuberShxg) {
        this.tuberShxg = tuberShxg;
    }

    public String getTuberJczjc() {
        return tuberJczjc;
    }

    public void setTuberJczjc(String tuberJczjc) {
        this.tuberJczjc = tuberJczjc;
    }

    public String getTuberZzqt() {
        return tuberZzqt;
    }

    public void setTuberZzqt(String tuberZzqt) {
        this.tuberZzqt = tuberZzqt;
    }

    public String getTuberHlfa() {
        return tuberHlfa;
    }

    public void setTuberHlfa(String tuberHlfa) {
        this.tuberHlfa = tuberHlfa;
    }

    public String getCardid() {
        return cardid;
    }

    public void setCardid(String cardid) {
        this.cardid = cardid;
    }

    public String getNextVisitDate() {
        return nextVisitDate;
    }

    public void setNextVisitDate(String nextVisitDate) {
        this.nextVisitDate = nextVisitDate;
    }

    public String getCreateorg() {
        return createorg;
    }

    public void setCreateorg(String createorg) {
        this.createorg = createorg;
    }

    public String getTargetSmoke() {
        return targetSmoke;
    }

    public void setTargetSmoke(String targetSmoke) {
        this.targetSmoke = targetSmoke;
    }

    public String getTargetDrink() {
        return targetDrink;
    }

    public void setTargetDrink(String targetDrink) {
        this.targetDrink = targetDrink;
    }

    public String getQdqxz() {
        return qdqxz;
    }

    public void setQdqxz(String qdqxz) {
        this.qdqxz = qdqxz;
    }

    public String getWzd() {
        return wzd;
    }

    public void setWzd(String wzd) {
        this.wzd = wzd;
    }

    public String getCreater() {
        return creater;
    }

    public void setCreater(String creater) {
        this.creater = creater;
    }

    public String getCreatetime() {
        return createtime;
    }

    public void setCreatetime(String createtime) {
        this.createtime = createtime;
    }

    public String getUpdateorg() {
        return updateorg;
    }

    public void setUpdateorg(String updateorg) {
        this.updateorg = updateorg;
    }

    public String getUpdatetime() {
        return updatetime;
    }

    public void setUpdatetime(String updatetime) {
        this.updatetime = updatetime;
    }

    public String getModified() {
        return modified;
    }

    public void setModified(String modified) {
        this.modified = modified;
    }

    public String getHappentime() {
        return happentime;
    }

    public void setHappentime(String happentime) {
        this.happentime = happentime;
    }

    public String getTuberDdryxz() {
        return tuberDdryxz;
    }

    public void setTuberDdryxz(String tuberDdryxz) {
        this.tuberDdryxz = tuberDdryxz;
    }

    public String getTuberPgysqm() {
        return tuberPgysqm;
    }

    public void setTuberPgysqm(String tuberPgysqm) {
        this.tuberPgysqm = tuberPgysqm;
    }

    public String getVisitWay() {
        return visitWay;
    }

    public void setVisitWay(String visitWay) {
        this.visitWay = visitWay;
    }

    public String getSmoke() {
        return smoke;
    }

    public void setSmoke(String smoke) {
        this.smoke = smoke;
    }

    public String getDrink() {
        return drink;
    }

    public void setDrink(String drink) {
        this.drink = drink;
    }

    /**
     * 肺结核第一次入户随访上传接口参数（基本信息）
     *
     * @param context 上下文
     * @return
     */
    public static List<TuberculosisBaseInfo> convertData(Context context) {
        List<TuberculosisBaseInfo> datas = new ArrayList<>();

        FDbManager fdb = FDbManager.getInstance(context);
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        if (null == NovaApplication.getUserInfo()) {
            return datas;
        }
        List<CD_TUBERCULOSIS_BASEINFO> infos = fdb.findAllByWhere(CD_TUBERCULOSIS_BASEINFO.class,
                "CARDID='" + NovaApplication.getUserInfo().getIDCARD() + "'");

        if (infos != null && !infos.isEmpty()) {
            for (CD_TUBERCULOSIS_BASEINFO info : infos) {
                TuberculosisBaseInfo tuberculosisBaseInfo = new TuberculosisBaseInfo();
                /*身份证号*/
                tuberculosisBaseInfo.setCardid(TextUtils.isEmpty(info.getCARDID()) ? "" : info.getCARDID().toUpperCase());
                if(TextUtils.isEmpty(tuberculosisBaseInfo.getCardid())){
                    if(!TextUtils.isEmpty(info.getPERSONALID())){
                        List<ARCHIVE_BASEINFO> ss=FDbManager.getInstance(context).findAllByWhere(ARCHIVE_BASEINFO.class,"ARCHIVEID='"+info.getPERSONALID()+"'");
                        if(ss.size()>0){
                            if(!ss.get(0).getPOPULATION_TYPE().contains("11")){
                                continue;
                            }
                            tuberculosisBaseInfo.setCardid(ss.get(0).getIDCARD().toUpperCase());
                        }else{
                            tuberculosisBaseInfo.setCardid("");
                        }

                    }
                }else{
                    List<ARCHIVE_BASEINFO> ss=FDbManager.getInstance(context).findAllByWhere(ARCHIVE_BASEINFO.class,"IDCARD='"+info.getCARDID()+"'");
                    if(ss.size()>0){
                        if(!ss.get(0).getPOPULATION_TYPE().contains("11")){
                            continue;
                        }
                    }
                }
                /*缺项值*/
                tuberculosisBaseInfo.setQdqxz("");
                /*随访时间*/
                if (info.getHAPPENTIME() != null) {
                    tuberculosisBaseInfo.setHappentime(formatter.format(info.getHAPPENTIME()));
                }
                /*随访方式*/
                tuberculosisBaseInfo.setVisitWay(TextUtils.isEmpty(info.getVISIT_WAY()) ? "" : info.getVISIT_WAY());
                /*患者类型*/
                tuberculosisBaseInfo.setTuberType(TextUtils.isEmpty(info.getTUBER_TYPE()) ? "" : info.getTUBER_TYPE());
                /*痰菌情况*/
                tuberculosisBaseInfo.setTuberTjqk(TextUtils.isEmpty(info.getTUBER_TJQK()) ? "" : info.getTUBER_TJQK());
                /*耐药情况*/
                tuberculosisBaseInfo.setTuberNyqk(TextUtils.isEmpty(info.getTUBER_NYQK()) ? "" : info.getTUBER_NYQK());
                /*症状及体征*/
                tuberculosisBaseInfo.setTuberZztz(TextUtils.isEmpty(info.getTUBER_ZZTZ()) ? "" : info.getTUBER_ZZTZ());
                /*化疗方案*/
                tuberculosisBaseInfo.setTuberHlfa(TextUtils.isEmpty(info.getTUBER_HLFA()) ? "" : info.getTUBER_HLFA());
                /*用法*/
                tuberculosisBaseInfo.setTuberYf(TextUtils.isEmpty(info.getTUBER_YF()) ? "" : info.getTUBER_YF());
                /*药品剂型*/
                tuberculosisBaseInfo.setTuberYpjx(TextUtils.isEmpty(info.getTUBER_YPJX()) ? "" : info.getTUBER_YPJX());
                /*督导人员*/
                tuberculosisBaseInfo.setTuberDdryxz(TextUtils.isEmpty(info.getTUBER_DDRYXZ()) ? "" : info.getTUBER_DDRYXZ());
                /*单独的居室*/
                tuberculosisBaseInfo.setTuberDdjs(TextUtils.isEmpty(info.getTUBER_DDJS()) ? "" : info.getTUBER_DDJS());
                /*透风情况*/
                tuberculosisBaseInfo.setTuberTfqk(TextUtils.isEmpty(info.getTUBER_TFQK()) ? "" : info.getTUBER_TFQK());
                /*吸烟：日吸烟量*/
                tuberculosisBaseInfo.setSmoke(TextUtils.isEmpty(info.getSMOKE()) ? "" : info.getSMOKE());
                /*吸烟：目标吸烟量*/
                tuberculosisBaseInfo.setTargetSmoke(TextUtils.isEmpty(info.getTARGET_SMOKE()) ? "" : info.getTARGET_SMOKE());
                /*饮酒：日饮酒*/
                tuberculosisBaseInfo.setDrink(TextUtils.isEmpty(info.getDRINK()) ? "" : info.getDRINK());
                /*饮酒：目标饮酒*/
                tuberculosisBaseInfo.setTargetDrink(TextUtils.isEmpty(info.getTARGET_DRINK()) ? "" : info.getTARGET_DRINK());
                /*取药地点*/
                tuberculosisBaseInfo.setTuberQydd(TextUtils.isEmpty(info.getTUBER_QYDD()) ? "" : info.getTUBER_QYDD());
                /*取药时间*/
                tuberculosisBaseInfo.setTuberQysj(TextUtils.isEmpty(info.getTUBER_QYSJ()) ? "" : info.getTUBER_QYSJ());
                /*服药记录卡的填写*/
                tuberculosisBaseInfo.setTuberJlk(TextUtils.isEmpty(info.getTUBER_JLK()) ? "" : info.getTUBER_JLK());
                /*服药方法及药品存放*/
                tuberculosisBaseInfo.setTuberFyff(TextUtils.isEmpty(info.getTUBER_FYFF()) ? "" : info.getTUBER_FYFF());
                /*肺结核治疗疗程*/
                tuberculosisBaseInfo.setTuberZllc(TextUtils.isEmpty(info.getTUBER_ZLLC()) ? "" : info.getTUBER_ZLLC());
                /*不规律服药危害*/
                tuberculosisBaseInfo.setTuberWh(TextUtils.isEmpty(info.getTUBER_WH()) ? "" : info.getTUBER_WH());
                /*服药后不良反应及处理*/
                tuberculosisBaseInfo.setTuberBlfy(TextUtils.isEmpty(info.getTUBER_BLFY()) ? "" : info.getTUBER_BLFY());
                /*治疗期间复诊查痰*/
                tuberculosisBaseInfo.setTuberFzct(TextUtils.isEmpty(info.getTUBER_FZCT()) ? "" : info.getTUBER_FZCT());
                /*外出期间如何坚持服药*/
                tuberculosisBaseInfo.setTuberRhfy(TextUtils.isEmpty(info.getTUBER_RHFY()) ? "" : info.getTUBER_RHFY());
                /*生活习惯及注意事项*/
                tuberculosisBaseInfo.setTuberShxg(TextUtils.isEmpty(info.getTUBER_SHXG()) ? "" : info.getTUBER_SHXG());
                /*密切接触者检查*/
                tuberculosisBaseInfo.setTuberJczjc(TextUtils.isEmpty(info.getTUBER_JCZJC()) ? "" : info.getTUBER_JCZJC());
                /*下次随访时间*/
                if (info.getNEXT_VISIT_DATE() != null) {
                    tuberculosisBaseInfo.setNextVisitDate(formatter.format(info.getNEXT_VISIT_DATE()));
                }
                /*评估医生签字*/
                tuberculosisBaseInfo.setTuberPgysqm(TextUtils.isEmpty(info.getTUBER_PGYSQM()) ? "" : info.getTUBER_PGYSQM());
                /*创建人*/
                tuberculosisBaseInfo.setCreater(TextUtils.isEmpty(info.getCREATER()) ? "" : info.getCREATER());
                /*创建时间*/
                if (info.getCREATETIME() != null) {
                    tuberculosisBaseInfo.setCreatetime(formatter.format(info.getCREATETIME()));
                }
                /*创建机构*/
                tuberculosisBaseInfo.setCreateorg(TextUtils.isEmpty(info.getCREATEORG()) ? "" : info.getCREATEORG());
                /*修改人*/
                tuberculosisBaseInfo.setModified(TextUtils.isEmpty(info.getMODIFIED()) ? "" : info.getMODIFIED());
                /*修改时间*/
                if (info.getUPDATETIME() != null) {
                    tuberculosisBaseInfo.setUpdatetime(formatter.format(info.getUPDATETIME()));
                }
                /*修改机构*/
                tuberculosisBaseInfo.setUpdateorg(TextUtils.isEmpty(info.getUPDATEORG()) ? "" : info.getUPDATEORG());
                /*添加list里面*/
                datas.add(tuberculosisBaseInfo);
            }
        }
        return datas;
    }
}
